<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    {include file="/layout/scriptload"}
    <title>入口链接</title>
    <style>
        .qrcode{
            padding: 7px;background: #f4f4f5;border: 1px solid #dddddd;cursor: pointer;margin-left: 5px;
        }
    </style>
</head>
<body>
<div class="box">
    <section class="content-header">
        <ol class="breadcrumb">
            <li><a><i class="fa fa-dashboard"></i> 自动化复粉</a></li>
            <li class="active">入口链接</li>
        </ol>
    </section>
    <!-- /.box-header -->
    <section class="content">
    <div class="box-body">
        <div id="example1_wrapper" class="dataTables_wrapper form-inline dt-bootstrap">
            <div class="row">
                <div class="col-sm-12">
                        <div id="example1_filter" class="dataTables_length">
                            <label>
                                <input type="search" id="keyword" class="form-control input-sm" placeholder="域名丶备注" aria-controls="example1">
                            </label>
                            <button type="button" id="search" class="btn margin" style="background: #18bc9c;color: #ffffff;">搜索</button>
                            <button type="button" onclick="relist()" title="刷新" class="btn bg-aqua margin"><i class="fa fa-refresh"></i></button>
                            <button type="button" id="add_link" onclick="toaddlink()" class="btn margin" style="background: #18bc9c;color: #ffffff;">添加</button>
                            <button type="button" id="del_link" class="btn bg-red margin"><i class="fa  fa-trash-o"></i> 删除</button>
                        </div>
                </div>
            </div>
            <div class="row">
                <div class="col-sm-12">
                    <table id="example1" class="table table-bordered table-striped dataTable" role="grid" aria-describedby="example1_info">
                        <thead>
                        <tr role="row">
                            <th class="sorting" tabindex="0" aria-controls="example1" rowspan="1" colspan="1" style="width: 60px;">
                                <input id="allchecked" type="checkbox" style="margin-left: 10px">
                            </th>
                            <th class="sorting" tabindex="0" aria-controls="example1" rowspan="1" colspan="1" style="width: 190px;">域名</th>
                            <th class="sorting_asc" tabindex="0" aria-controls="example1" rowspan="1" colspan="1" style="width: 297px;">入口链接</th>
                            <th class="sorting" tabindex="0" aria-controls="example1" rowspan="1" colspan="1" style="width: 322px;">屏蔽城市</th>
                            <th class="sorting" tabindex="0" aria-controls="example1" rowspan="1" colspan="1" style="width: 257px;">状态</th>
                            <th class="sorting_asc" tabindex="0" aria-controls="example1" rowspan="1" colspan="1" style="width: 297px;">权重</th>
                            <th class="sorting" tabindex="0" aria-controls="example1" rowspan="1" colspan="1" style="width: 190px">备注</th>
                            <th class="sorting" tabindex="0" aria-controls="example1" rowspan="1" colspan="1" style="width: 190px">循环方式</th>
                            <th class="sorting" tabindex="0" aria-controls="example1" rowspan="1" colspan="1" style="width: 190px">创建时间</th>
                            <th class="sorting" tabindex="0" aria-controls="example1" rowspan="1" colspan="1" style="width: 190px;">操作</th>
                        </tr>
                        </thead>
                        <tbody id="tb">
                       </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
    <!-- /.box-body -->
    </section>
</div>
</body>
<script>
    var _keyword = '';
    $(function(){
        getlist(_keyword);
        $('#search').click(function(){
            table.destroy();
            var keyword = $('#keyword').val();
            getlist(keyword);
        });
        //反选
        $('#allchecked').click(function(){
            $("[name = checkboxed]:checkbox").each(function () {
                $(this).prop("checked", !$(this).prop("checked"));
            });
        });
        //删除
        $('#del_link').click(function(){
            var _ids =[];
            $('input[name="checkboxed"]:checked').each(function(){
                _ids.push($(this).val());
            });
            $.ajax({
                type: 'post',
                cache: false,
                url:'{:url("admin/Replyfans/delEntryLink")}',
                data: {ids:_ids},
                success: function(data) {
                    if(data.code == 0){
                        layerAlert('删除成功',function () {
                            relist();
                        });
                    }else{
                        layerAlert('删除失败');
                    }
                }
            })
        })
    })
    function getlist(_keyword)
    {
        $.ajax({
            type: 'post', cache: false,
            url:'{:url("admin/Replyfans/getLinkList")}',
            data: {keyword:_keyword},
            success: function(data) {
                if(data.code=="0")
                {
                    $("#tb tr").remove();
                    $.each(data.info,function(index,item){
                        var html='<tr role="row" class="odd" id="tr_'+item.id+'">';
                        html+='<td style="vertical-align: middle;"><input name="checkboxed" value="'+item.id+'" type="checkbox" style="margin-left: 10px"></td>';
                        html+='<td style="vertical-align: middle;">'+item.linkname+'</td>';
                        html+='<td style="vertical-align: middle;"><input class="form-control" type="" value="'+item.entry_link+'"><i entrylink="'+item.entry_link+'" class="fa qrcode fa-random"></i></td>';
                        html+='<td style="vertical-align: middle;">'+item.shield_city+'</td>';
                        if(item.status=="1")
                            html+='<td style="vertical-align: middle;"><span style="color: #18bc9c;">有效</span></td>';
                        else
                            html+='<td style="vertical-align: middle;"><span style="color: red;">无效</span></td>';
                        if(item.is_weight=="1")
                            html+='<td style="vertical-align: middle;"><span style="color: #18bc9c;">随机</span></td>';
                        else
                            html+='<td style="vertical-align: middle;"><span style="color: #18bc9c;">权重</span></td>';
                        html+='<td style="vertical-align: middle;">'+item.remark+'</td>';
                        html+='<td style="vertical-align: middle;">'+item.circulation+'</td>';
                        html+='<td style="vertical-align: middle;">'+item.createtime+'</td>';
                        html+='<td style="vertical-align: middle;text-align: center">';
                        html+='<div class="btn-group">';
                        html+=' <button onclick="toopen('+item.id+')" type="button" title="跳转链接" class="btn" style="background: #18bc9c;color: #ffffff;"><i class="fa fa-recycle"></i></button>';
                        html+=' <button onclick="toedit('+item.id+')" title="编辑" type="button" class="btn bg-aqua"><i class="fa fa-edit"></i></button>';
                        html+='</div>';
                        html+='</td>';
                        html+='</tr>';
                        $("#tb").append(html);
                    });
                    $('.fa-random').bind("click",function(){
                        var _entrylink = $(this).attr('entrylink');
                        window.open(_entrylink);
                    })
                    table = $('#example1').DataTable({
                        "paging": true,
                        "lengthChange": false,
                        "lengthMenu": [[10],[10]],
                        "searching": false,
                        "ordering": false,
                        "info": true,
                        "language": {
                            "info": "展示第 <span style='color: red;'>_START_</span> 到 <span style='color: red;'>_END_</span> 个 共 <span style='color: red;'>_TOTAL_</span> 个公众号",
                            "paginate": {
                                "previous": "上一页",
                                "next": "下一页"
                            }
                        },
                        "autoWidth": true,
                    });
                }
            },
            error: function() {
                alert("发生系统错误,请与管理员联系！");
            }
        });
    }
    //添加
    function toaddlink()
    {
        url = "{:url('replyfans/addEntryLink')}";
        layerWindow('自动化复粉->入口链接->添加链接',url,'40%','80%');
    }
    //跳转链接
    function toopen(_id) {
        url = "{:url('replyfans/linkDetail')}?id=" + _id;
        layerWindow('自动化复粉->入口链接->跳转链接',url,'80%','80%');
    }
    function relist()
    {
        table.destroy();
        getlist(_keyword);
    }
</script>
</html>